<?php

namespace app\admin\model;

use think\Model;

class Admin extends Model
{
    use TraitModel;
    protected $observerClass = 'app\admin\event\Admin';

    public function setPasswordAttr($value)
    {
        return 'comma'.md5($value);
    }

    public function CheckData($data, $edit = 1)
    {
        $data = [
            'name' => $data['name'],
            'password' => 'comma'.md5($data['password']),
        ];
        $res = $this->where($data)->find();
        if ($res) {
            if ($edit) {
                $group = model('admin/group')->get($res->gid);
                session('adminId', $res->id);
                session('adminGid', $res->gid);
                session('adminName', $res->name);
                session('adminLevel', $group->level);
            }

            return true;
        } else {
            return false;
        }
    }
}
